/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Project;

import java.util.ArrayList;
import javax.swing.ListSelectionModel;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author PHINGUYEN
 */
public class TableModel extends AbstractTableModel{
    ArrayList<String> clName;
    ArrayList<Student> data;

    public TableModel() {
    }

    public TableModel(ArrayList<String> clName, ArrayList<Student> data) {
        this.clName = clName;
        this.data = data;
    }
    
    
    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return clName.size();
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Student sd = data.get(rowIndex);
        if(columnIndex == 0){
            return sd.getID();
        }
        if(columnIndex == 1){
            return sd.getFirstName();
        }
        if(columnIndex == 2){
            return sd.getLastName();
        }
        if(columnIndex == 3){
            return sd.getMail();
        }
        if(columnIndex == 4){
            return sd.getPhone();
        }
        return "";
    }

    @Override
    public String getColumnName(int column) {
        return clName.get(column);
    }
    
    public Student getStudentAtRow(int rowIndex){
        Student sd = data.get(rowIndex);
        return sd;
    }
}
